package com.qianbei.common.dialog;

import android.content.Context;
import android.util.TypedValue;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.qianbei.R;
import com.qianbei.common.adapter.CommonAdapter;
import com.qianbei.common.adapter.ViewHolder;

import java.util.List;

/**
 *
 * Created by user on 16/9/29.
 */

public class CommonMenuAdapter extends CommonAdapter<Integer> {

    private int mLeftMargin;
    private int mLineHeight;
    private int mMaxLineHeight;

    private int mMenuTextColor;
    private int mMenuPosition;

    public CommonMenuAdapter(Context context, List<Integer> data, int itemLayoutId) {
        super(context, data, itemLayoutId);
        mLeftMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,10,mResources.getDisplayMetrics());
        mMaxLineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,7,mResources.getDisplayMetrics());
        mLineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,1,mResources.getDisplayMetrics());
    }

    @Override
    public void convert(ViewHolder helper, Integer item, int position) {

        helper.setText(R.id.tv_item,mResources.getString(item));

        TextView text = helper.getView(R.id.tv_item);
        TextView line = helper.getView(R.id.tv_line);
        TextView maxLine = helper.getView(R.id.tv_line_width);

        text.setText(mResources.getString(item));
        if (position == mMenuPosition){
            text.setTextColor(mResources.getColor(mMenuTextColor));
        }else{
            text.setTextColor(mResources.getColor(R.color.color_606060));
        }

        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) line.getLayoutParams();

        if (position == 0){
            line.setVisibility(View.GONE);
            maxLine.setVisibility(View.GONE);
        }else if(position == getCount() - 1){
            maxLine.setVisibility(View.VISIBLE);
            line.setVisibility(View.GONE);

            params.leftMargin = 0;
            params.rightMargin = 0;
        }else{
            line.setVisibility(View.VISIBLE);
            maxLine.setVisibility(View.GONE);

            params.leftMargin = mLeftMargin;
            params.rightMargin = mLeftMargin;
        }

        line.setLayoutParams(params);
    }


    /**
     * 设置menu菜单 文字颜色
     *
     * @param position
     * @param color
     */
    public void setMenuTextColorByPosition(int position,int color){
        this.mMenuTextColor = color;
        this.mMenuPosition = position;
    }
}
